package com.yugong.controller;

import com.github.pagehelper.PageInfo;
import com.yugong.common.Result;
import com.yugong.entity.vo.request.StudentRequestVO;
import com.yugong.entity.vo.response.StudentListResponseVO;
import com.yugong.service.StudentService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 学生控制器类
 *
 * @author yugong
 * @date 2024/2/18
 */
@RestController
@RequestMapping("/api/student")
public class StudentController {
    @Resource
    private StudentService studentService;

    /**
     * 根据学生姓名查询学生信息
     *
     * @param pageNum     当前页
     * @param pageSize    当前页的数据个数
     * @param studentName 学生姓名
     * @return 学生信息
     */
    @GetMapping("/find-student-page-admin")
    public Result findStudentPageAdmin(@RequestParam(defaultValue = "1") Integer pageNum,
                                       @RequestParam(defaultValue = "5") Integer pageSize,
                                       @RequestParam String studentName) {
        PageInfo<StudentListResponseVO> studentListResponseVOPageInfo
                = studentService.findStudent(pageNum, pageSize, studentName);
        return Result.success(studentListResponseVOPageInfo);
    }

    /**
     * 根据学生姓名查询学生信息
     *
     * @param pageNum     当前页
     * @param pageSize    当前页的数据个数
     * @param studentName 学生姓名
     * @return 学生信息
     */
    @GetMapping("/find-student-page-order-class-admin")
    public Result findStudentPageOrderClassAdmin(@RequestParam(defaultValue = "1") Integer pageNum,
                                                 @RequestParam(defaultValue = "5") Integer pageSize,
                                                 @RequestParam String studentName) {
        PageInfo<StudentListResponseVO> studentListResponseVOPageInfo
                = studentService.findStudent(pageNum, pageSize, studentName);
        return Result.success(studentListResponseVOPageInfo);
    }

    /**
     * 删除学生
     *
     * @param studentNo 学号
     * @return 数据库影响行数
     */
    @DeleteMapping("/delete-student/{studentNo}")
    public Result deleteStudent(@PathVariable String studentNo) {
        int deleteFlag = studentService.deleteStudent(studentNo);
        return Result.success(deleteFlag);
    }

    /**
     * 查询学生个人信息
     *
     * @param studentNo 学号
     * @return 学生个人信息
     */
    @GetMapping("/student-info/{studentNo}")
    public Result studentInfo(@PathVariable String studentNo) {
        StudentListResponseVO studentListResponseVO = studentService.studentInfo(studentNo);
        return Result.success(studentListResponseVO);
    }

    /**
     * 修改信息
     *
     * @param studentRequestVO 学生请求实体类
     * @return 响应码
     */
    @PutMapping("/update-info")
    public Result updateInfo(@RequestBody StudentRequestVO studentRequestVO) {
        int updateFlag = studentService.updateInfo(studentRequestVO);
        return Result.success(updateFlag);
    }

    /**
     * 学生报名
     *
     * @param studentRequestVO 学生请求实体类
     * @return 响应码
     */
    @PutMapping("/student-join")
    public Result studentJoin(@RequestBody StudentRequestVO studentRequestVO) {
        int updateFlag = studentService.studentJoin(studentRequestVO);
        return Result.success(updateFlag);
    }

    /**
     * 审核学生列表
     *
     * @param pageNum           当前页
     * @param pageSize          当前页数据个数
     * @param orderClassName    班名
     * @param orderClassAdminNo 订单班管理员工号
     * @return 审核学生列表
     */
    @GetMapping("/check-student-page/{orderClassAdminNo}")
    public Result checkStudentPage(@RequestParam(defaultValue = "5") Integer pageNum,
                                   @RequestParam(defaultValue = "1") Integer pageSize,
                                   @RequestParam String orderClassName,
                                   @PathVariable String orderClassAdminNo) {
        PageInfo<StudentListResponseVO> studentListResponseVOPageInfo = studentService.checkStudentPage(pageNum, pageSize, orderClassName, orderClassAdminNo);
        return Result.success(studentListResponseVOPageInfo);
    }

    /**
     * 审核学生
     *
     * @param studentRequestVO 学生请求实体类
     * @return 响应码
     */
    @PutMapping("/check-student")
    public Result checkStudent(@RequestBody StudentRequestVO studentRequestVO) {
        int updateFlag = studentService.checkStudent(studentRequestVO);
        return Result.success(updateFlag);
    }

    /**
     * 学生查看个人评价
     *
     * @param studentNo 学号
     * @return 个人评价
     */
    @GetMapping("/evaluate-student/{studentNo}")
    public Result evaluateStudent(@PathVariable String studentNo) {
        String info = studentService.evaluateStudent(studentNo);
        return Result.success(info);
    }
}
